<template>
  <div>
    <h3>home</h3>
    <button @click="dodo">测试</button>
    <input v-model="text" />
    <button @click="send">测试发送 </button>
    <button @click="opennew">主线程打开窗口 </button>
    <router-link :to="{ path: '/about' }">点我</router-link>

    <button @click="sqlite">sqlite </button>
  </div>
</template>

<script >
export default {
  data() {
    return {
      text: null
    }
  },
  mounted() {
    // console.log('home', window)
    // const electron = window.require('electron') //引用electron
    // const fs = window.require('fs') //引用Node模块fs
    // const remote = window.require('@electron/remote')
    // console.log(electron, fs, remote)
    // // console.log(remote.BrowserWindow)

    // const { contextBridge, ipcRenderer } = window.require('electron/renderer')
    // ipcRenderer.on('some-response', (event, arg) => {
    //   console.log(arg); // 打印主进程回复的消息
    // });
  },
  methods: {
    sqlite(){
      const { contextBridge, ipcRenderer } = window.require('electron/renderer')
      console.log('sqlite')
      ipcRenderer.send('sqlitenew', 'new');
    },
    opennew() {
      const { contextBridge, ipcRenderer } = window.require('electron/renderer')
      ipcRenderer.send('opennew', {
        url: 'http://localhost:8084/#/',
      });
    },
    send() {
      const { contextBridge, ipcRenderer } = window.require('electron/renderer')
      ipcRenderer.send('some-event', this.text);
    },
    createWindow(BrowserWindow) {
      console.log(33)
      // Create the browser window.
      const mainWindow = new BrowserWindow({
        width: 1000,
        height: 400,
        webPreferences: {
          enableRemoteModule: true,
          nodeIntegration: true,
          contextIsolation: false,
          webSecurity: false,
        }
      })


      // and load the index.html of the app.
      mainWindow.loadURL('http://localhost:8084/#/')


    },
    dodo() {
      const { remote } = window.require("electron");
      console.log(remote)
      // const remote = window.require('@electron/remote')
      // console.log(remote, 'remote')
      let BrowserWindow = remote.BrowserWindow

      this.createWindow(BrowserWindow)
    }
  }
}

</script>